<?php 
	class Cms_Captcha_Image extends Zend_Captcha_Image{

		public $_imgDir = null;//images dir
		public $_imgUrl = null;//images url
		//khởi tạo captcha
		public function __construct(){						
			$this->_imgDir= PUBLIC_PATH.'/captcha';			
			//$this->_imgUrl=Zend_Controller_Front::getInstance()->getBaseUrl()."/public/captcha/";
			$this->_imgUrl= PUBLIC_RESOURCE.'/captcha';
			//set width image
			
			$this->setWidth(80);
			//set height image
			$this->setHeight(40);
			
			//set wordlen
			$this->setWordlen(4);
			
			//set timeout
			$this->setTimeout(200);
			
			//set font 
			$this->setFont(PUBLIC_PATH."/font/georgia.ttf");			
			$this->setFontSize(14);
			
			$this->setDotNoiseLevel(0);
			$this->setLineNoiseLevel(0);
			$this->setGcFreq(5);
			
			//set url iamge
			$this->setImgDir($this->_imgDir);
			$this->setImgUrl($this->_imgUrl);
			
			//create
			$this->generate();
			
			//save captcha to session
			$captchaSession = new Zend_Session_Namespace("Zend_Form_Captcha_".$this->getId());
			$captchaSession->word = $this->getWord();
		}
		
		//remove captcha
		public function removeCaptcha($captchaID,$options=false){
			$captchafile = $captchaID.$this->getSuffix();
			if($options['exception']==true){//xóa tất cả các file ngoại trừ file hiện tại
				$fileList = scandir($this->_imgDir);
				foreach($fileList as $file){
					if($captchafile!=$file){
						$linkfile = $this->_imgDir.$file;
						@unlink($linkfile);
					}
				}
			}else {
				//xóa file hiện tại
				@unlink($this->_imgDir."/".$captchafile);
			}
		}
		
	}
?>